//活动轮播
var activitySwiper = new Swiper('.activity-swiper', {
		freeMode : true,
		slidesPerView:'4',
})
//点击标题
$(".myheader").on('click','.title',function(){
	var $this= $(this);
	if($this.hasClass("slided")){
		$this.removeClass("slided");
		$this.find(".slide-down").css("transform","rotate(180deg)");
	}else{
		$this.addClass("slided");
		$this.find(".slide-down").css("transform","rotate(270deg)");
	}
	$(".slide-container").slideToggle('fast');
})
window.onscroll = function(){
	//懒加载
	lazyLoad($(".lazy[data-load='false']"));
}
//点击上拉
$(".slide-container").on("click","a",function(){
	$(".myheader .title").find("span").html($(this).html())
	$(".slide-container").slideToggle('fast');
	$(".myheader").find(".title").removeClass("slided").find(".slide-down").css("transform","rotate(180deg)");
})
//点击分类
$(".classify").on('click',function(){
	$(".classify-container").before("<div class='shadow'></div>").css("right","0");
	$("body").css("overflow-y","hidden");
	clickShadow(function(){
		$(".classify-container").css("right","-8rem");
		$("body").css("overflow-y","auto");
	})
})
//点击取消
$(".no").on('click',function(){
	$(".classify-container").css("right","-8rem");
	$(".shadow").remove();
	$("body").css("overflow-y","auto");
})
//秒杀
$(".item_list").find(".rush").each(function(){
	var id  = $(this).attr("id");
	new timer().showTime({
		container_id:'#'+id,
		start:parseInt($("#"+id).find(".time-container").attr("data-start")),
		now:parseInt($("#"+id).find(".time-container").attr("data-now")),
		end:parseInt($("#"+id).find(".time-container").attr("data-end")),
		callback:function(){
			console.log(this.container_id);
		$(this.container_id).fadeOut(function(){
			$(this).remove();
			
		})
	}
	}).countDown();
})
//一级分类
var typeSwiper = new Swiper('.type-swiper', {
		freeMode : true,
		slidesPerView:'3',
		preventClicksPropagation:true,
		initialSlide :$(".type-swiper").find(".active").parents("li").index(),
})
//点击一级分类
$(".type-swiper").on("click","span",function(e){
	if($(this).hasClass("active")){             
		$(this).removeClass("active");
		$(".second-type-list").empty();
	}else{
		$(".type-swiper").find("span.active").removeClass("active");
		$(this).addClass("active");
		var oneProductCategoryId = $(this).parent("a").attr("data-oneProductCategoryId");
		$.ajax({
			type:"get",
			url:base_url+"customer/getClassifyMsgByOneId",
			data:{"oneProductCategoryId":oneProductCategoryId},
			async:false,
			success:function(data){
				$(".second-type-list").empty();
				var html = "";
				for(var i=0;i<data.length;i++){
					html = html + '<div class="second-type">'
					+'<p class="second-type-title">'
					+	'<span class="second-type-radio" data-twoProductCategoryId="'+data[i].twoProductCategory.productCategoryId+'"></span>'
					+	'<span>'+data[i].twoProductCategory.productCategoryName+'</span>'
					+	'<span class="floatRight">'
					+		'<i class="iconfont">&#xe66d;</i>'
					+	'</span>'
					+'</p>'
					+'<div class="third-type-list clearfloat">';
					var threeProductCategories = data[i].threeProductCategories;
					for(var j=0;j<threeProductCategories.length;j++){
						html = html + '<span class="third-type" data-threeProductCategoryId="'+threeProductCategories[j].productCategoryId+'">'
							+ '<img src="'+threeProductCategories[j].productCategoryUrl+'" name="threeProductCategory" data-id="'+threeProductCategories[j].productCategoryId+'" data-name="'+threeProductCategories[j].productCategoryName+'"/>'
							+ '<span class="third-type-name">'+threeProductCategories[j].productCategoryName+'</span>'
							+ '</span>'
					}
					html = html + '</div></div>'
				}
				$(".second-type-list").append(html);
			
			},
			error:function(){
			}
		});
	}
})
//点击二级分类
$(".second-type-list").on("click",".second-type-title",function(e){
	var $this = $(this);
	var radio = $this.find(".second-type-radio");
	//判断状态
	if(radio.hasClass("active")){
//		radio.removeClass("active");
	}else{
		$(".second-type-radio.active").removeClass("active");
		radio.addClass("active");
		//重置三级
		$(".second-type-list").find(".third-type.active").removeClass("active");
	}
	$this.parents(".second-type-list").find(".third-type-list").slideUp('fast');
	//判断动作
	if($this.parent(".second-type").find(".third-type-list").css("display")=="none"){
		$this.parent(".second-type").find(".third-type-list").slideToggle('fast');
	}
})
//点击三级分类
$(".second-type-list").on("click",".third-type",function(){
	var $this = $(this)
	if($this.hasClass("active")){
		$this.removeClass("active");
	}else{
		$(".second-type-list").find(".third-type.active").removeClass("active");
		$this.addClass("active");
	}
})

//点击确认键进行查询
$(".yes").click(function(){
	var productType = $("#productTypeMessage").attr("data-productType");
	var activityName = $("#productTypeMessage").attr("data-activityName");
	var firstProductCategoryId =$(".type-swiper").find("span.active").parent("a").attr("data-oneProductCategoryId");
	var secondProductCategoryId = $(".second-type-radio.active").attr("data-twoProductCategoryId");
	var thirdProductCategoryId = $(".second-type-list").find(".third-type.active").attr("data-threeProductCategoryId");
	if(firstProductCategoryId!=null&&firstProductCategoryId!=""){
		if(secondProductCategoryId!=null&&secondProductCategoryId!=""){
			if(thirdProductCategoryId!=null&&thirdProductCategoryId!=""){
				var json = {
						"productType":productType,
						"activityName":activityName,
						"firstProductCategoryId":firstProductCategoryId,
						"secondProductCategoryId":secondProductCategoryId,
						"thirdProductCategoryId":thirdProductCategoryId,
						"searchType":""
				}
				var jsonStr = JSON.stringify(json);
				window.location.href = base_url + "customer/getPlatformActivityClassify?jsonStr="+jsonStr;
			}else{
				var json = {
						"productType":productType,
						"activityName":activityName,
						"firstProductCategoryId":firstProductCategoryId,
						"secondProductCategoryId":secondProductCategoryId,
						"searchType":""
				}
				var jsonStr = JSON.stringify(json);
				window.location.href = base_url + "customer/getPlatformActivityClassify?jsonStr="+jsonStr;
			}
		}else{
			var json = {
					"productType":productType,
					"activityName":activityName,
					"firstProductCategoryId":firstProductCategoryId,
					"searchType":""
			}
			var jsonStr = JSON.stringify(json);
			window.location.href = base_url + "customer/getPlatformActivityClassify?jsonStr="+jsonStr;
		}
	}else{
		var json = {
				"productType":productType,
				"activityName":activityName,
				"searchType":""
		}
		var jsonStr = JSON.stringify(json);
		window.location.href = base_url + "customer/getPlatformActivityClassify?jsonStr="+jsonStr;
	}
});

//点击活动
$(".activity").on("click",function(){
	$(this).find(".activity-list").slideToggle('fast');
})
//格式化图片
FormatImg($(".p-img"),$(".p-img").parents(".product-img"));